package com.jerry.Future;

public class FutureServiceImpl<T> implements FutureService {
    @Override
    public Future<?> submit(Runnable runnable) {
        FutureTask<Void> voidFutureTask = new FutureTask<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                runnable.run();
                voidFutureTask.finishTask(null);
            }
        });
        return voidFutureTask;
    }

    @Override
    public <IN, OUT> Future<OUT> submit(Task<IN, OUT> inoutTask, IN input) {
        FutureTask<OUT> outFutureTask = new FutureTask<>();

        new Thread(new Runnable() {
            @Override
            public void run() {
                OUT out = inoutTask.get(input);
                outFutureTask.finishTask(out);
            }
        }).start();
        return outFutureTask;
    }
}
